[ANN] DiscussMethods
Return to home page
Comments Loading...
2004-10-22

With Travis Griggs, I've just made a new goodie called DiscussMethods. The basic idea is to be able to post code snippits in to our blogs from Smalltalk while keeping the syntax colouring that we get in our development environment.

There is a goodie called RBCodeHighlighting which provides on-the-fly colouring of methods as you edit them. It's great, it parses the method as you code and uses the parse tree to apply colouring to the Core.Text object in the widget.

Using the Core.Text object, we then extract that styling information in to some basic HTML, then put some CSS over the top of it to make it look colourful. Here's the result:

layoutText
	self pane displayText isEmpty ifTrue: [^self pane nextText: nil].
	self needsLayout ifFalse: [^self].
	self owner == self ifFalse: [^self layoutParent accept: self].
	self pane makeTexts.
	self pane allPartialTexts do: [:text |
		(self canFitOnLine: text) ifFalse: [self layoutParent layoutParent newLine].
		self layoutParent layoutParent lastLine accept: text frame.
		text displayText last = Character cr ifTrue: [self layoutParent layoutParent newLine]].

Naturally, this method should be refactored, but it served as a good colourful example.

Once it's loaded you can right click on a method name in the refactoring browser an dchoose 'Copy as Styled HTML'. The other option available is 'View as Styled HTML in WithSTyle' - this is only live if you have WithStyle loaded. It's more for a preview of what you're about to copy than for anything else.